package com.multidisplay.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.multidisplay.bo.LoginBo;
import com.multidisplay.bo.ResultBo;
import com.multidisplay.po.BaseData;
import com.multidisplay.po.User;
import com.multidisplay.pojo.AddUser;
import com.multidisplay.pojo.Login;
import com.multidisplay.service.LoginService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("LoginPageService")
public class LoginServiceImpl implements LoginService {
    @Resource
    private UserServiceImpl userService;
    private List<LoginBo> loginBos;

    @Override
    public ResultBo<LoginBo> login(Login login) {
        ResultBo<LoginBo> resultBo=new ResultBo<>();
        LoginBo loginBo=new LoginBo();
        List<User> user=userService.findByuId(login.getUsername());

        if(user.isEmpty()){
            loginBo.setSuccess(false);
            loginBo.setMsg("用户名不存在");
            loginBos.add(loginBo);
            resultBo.setData(loginBos);
        }
        if(user.get(0).getPassword()!=login.getPassword()){
            loginBo.setSuccess(false);
            loginBo.setMsg("密码错误");
            loginBos.add(loginBo);
            resultBo.setData(loginBos);
        }
        resultBo.setCode(0);
        resultBo.setMsg("");
        resultBo.setCount(0);
        return resultBo;
    }

    @Override
    public LoginBo register(AddUser addUser) {
        LoginBo loginBo=new LoginBo();
        try{
            userService.addUser(addUser);
        }catch (Exception e)
        {
            loginBo.setSuccess(false);
            return loginBo;
        }
        loginBo.setSuccess(true);
        return loginBo;
    }
}
